﻿using B.S.Data.MES.API.Applications.BaseData.Command.ProductCommand;
using B.S.Domain.CangKu;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.ProductCommandHandler
{
    public class GetGoodCommandHandler : IRequestHandler<GetGoodCommand, APIRequst<APIPageing<List<Finished_ProductTest>>>>
    {
        private readonly IBaseRepository<Finished_ProductTest> _goodinformationRepository;
        public GetGoodCommandHandler(IBaseRepository<Finished_ProductTest> goodinformationRepository)
        {
            _goodinformationRepository = goodinformationRepository;
        }
        public Task<APIRequst<APIPageing<List<Finished_ProductTest>>>> Handle(GetGoodCommand request, CancellationToken cancellationToken)
        {
            var code = _goodinformationRepository.GetAll();

            var recordCount = code.Count();
            var pageCount = (int)Math.Ceiling(recordCount * 1.0 / request.PageSize);

            code = code.OrderByDescending(x => x.FinisheId).Skip((request.PageIndex - 1) * request.PageSize).Take(request.PageSize);
            APIPageing<List<Finished_ProductTest>> paing = new APIPageing<List<Finished_ProductTest>>();
            paing.Total = recordCount;
            paing.TotalCount = pageCount;
            paing.Data=code.ToList();
            return Task.FromResult(new APIRequst<APIPageing<List<Finished_ProductTest>>> {
            
                Code=RequstCode.成功,
                Msg=RequstCode.成功.ToString(),
                Data=paing,
            
            });

        }
    }
}
